package com.eat.mapper;

import com.github.pagehelper.Page;
import com.eat.annotation.AutoFill;
import com.eat.dto.SetmealDTO;
import com.eat.dto.SetmealPageQueryDTO;
import com.eat.entity.Setmeal;
import com.eat.enumeration.OperationType;
import com.eat.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    @AutoFill(OperationType.INSERT)
    void saveSetmeal(Setmeal setmeal);



    Page<SetmealVO> page(SetmealPageQueryDTO setmealPageQueryDTO);

    @Update("update setmeal set status=#{status} where id = #{id}")
    void putStatus(Integer status, Long id);

    @AutoFill(OperationType.UPDATE)
    void putSetmeal(Setmeal setmeal);

    @Select("select * from setmeal where id =#{id}")
    SetmealDTO getById(Long id);

    void deleteByIds(List<Long> ids);

    @Select("select * from setmeal where category_id = #{categoryId} and status = #{status}")
    List<Setmeal> getByCategoryId(Setmeal setmeal);

    /**
     * 根据条件统计套餐数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
